fix(hetzner): register env-scoped SSH keys once across realization scopes#154
Merged
Merged
Conversation
…opes
program.Run builds one HetznerCompute per realization scope (the region-less
global slice plus each region), each with its own SSH-key dedup cache. Hetzner
SSH keys are account-global and named with no region slug
(wardnet-<env>-key-{user,deploy}), so every scope registered the same URN and
the first real cross-scope deploy failed at preview with
"Duplicate resource URN '…SshKey::wardnet-<env>-key-user'".
Share one SSHKeyCache across every HetznerCompute of a run (threaded
program.Run → BuildRegistry → NewCompute) so the keys register exactly once.
Pin them to a dedicated, fixed-name provider (hcloud-ssh-keys) instead of the
winning scope's region-scoped provider, so the account-global key's owning
provider stays stable when the scope set or realization order changes. Drop the
region-slug/container labels from the shared key (env-scoped → no scope-specific
label). Assumes one Hetzner account per env.
Add regression tests at the compute and registry layers (dedup + dedicated
provider) and a rule documenting the invariant.
Claude-Session: https://claude.ai/code/session_017Kyd98NzojozMZ19d5UCZ2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The first real cross-scope deployment (
wardnet-infrastructurePR #31) failed atinforge previewwith:program.Runbuilds oneHetznerComputeper realization scope (the region-less global slice plus each region), each with its own SSH-key dedup cache. Hetzner SSH keys are account-global and named with no region slug (wardnet-<env>-key-{user,deploy}, vianaming.GlobalResource), so every scope registered the same URN. The dedup never spanned scopes.This is the sibling of the already-documented
registry-provider-names-are-region-scopedbug: providers legitimately need a unique URN per scope, whereas these env-scoped keys must be created exactly once total.Fix
SSHKeyCacheacross everyHetznerComputeof a run, threadedprogram.Run→BuildRegistry→NewCompute, so the keys register exactly once.hcloud-ssh-keys) instead of whichever scope's region-scoped provider ran first. This keeps the account-global key's owning provider stable when the scope set or realization order changes (otherwise Pulumi could see the provider reference move between runs and replace a resource every server depends on). Because the cache dedups creation to a single caller, this provider registers exactly once and never collides on URN.Tests
providers/hetzner—TestEnsureSshKeysSharedAcrossInstances: two instances sharing a cache return identical key objects.internal/registry—TestSshKeysRegisterOncePerEnvAcrossScopes: drives two registries over one Pulumi context through the realCompute().Create()path; asserts each key registers exactly once and under the dedicatedhcloud-ssh-keysprovider. Both assertions were verified to fail when the fix is reverted..agents/rules/ssh-keys-register-once-across-scopes.md.go build ./...,go test -race ./..., andgolangci-lint run ./...all pass.Merge Commit Message
https://claude.ai/code/session_017Kyd98NzojozMZ19d5UCZ2